package fr.epsi.BDD;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Florent Baudon on 15/05/2014.
 */
public class BDDHelper extends SQLiteOpenHelper {

    public BDDHelper(Context context) {
        super(context, "LittleHotel.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //Creation de la table tache
        db.execSQL("CREATE TABLE taches (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "nom TEXT NOT NULL, " +
                "service TEXT NOT NULL, " +
                "nomemploye TEXT NOT NULL, " +
                "prenomemploye TEXT NOT NULL, " +
                "datedeb TEXT NOT NULL,  " +
                "datefin TEXT NOT NULL)");

        //Creation table absences
        db.execSQL("CREATE TABLE absences (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "nomemploye TEXT NOT NULL, " +
                "prenomemploye TEXT NOT NULL, " +
                "raison TEXT NOT NULL, " +
                "datedeb TEXT NOT NULL, " +
                "datefin TEXT NOT NULL)");

        //Creation table employes
        db.execSQL("CREATE TABLE employes (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "nom TEXT NOT NULL, " +
                "prenom TEXT NOT NULL, " +
                "contrat TEXT NOT NULL, " +
                "service TEXT NOT NULL, " +
                "tempstravail INTEGER NOT NULL)");

        //Creation table services
        db.execSQL("CREATE TABLE services (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "nom TEXT NOT NULL)");
        db.execSQL("INSERT INTO services(nom) VALUES('Menage')");
        db.execSQL("INSERT INTO services(nom) VALUES('Reception')");
        db.execSQL("INSERT INTO services(nom) VALUES('Maintenance')");

        //Creation table tacheHebdo
        db.execSQL("CREATE TABLE listeTacheHebdo(_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "nom TEXT NOT NULL, " +
                "description TEXT NOT NULL, " +
                "nomService TEXT NOT NULL, " +
                "tempstravail INTEGER NOT NULL, " +
                "jour TEXT NOT NULL," +
                "heureDebut TEXT NOT NULL)");
        db.execSQL("INSERT INTO listeTacheHebdo(nom, description, nomService, tempstravail, jour, heureDebut) VALUES('Menage du lundi','Coucou','Menage', 2, 'Lundi','10:00')");

        //Creation table uneTache
        //dd-mm-aaaa
        db.execSQL("CREATE TABLE uneTache (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "idtachehebdo INTEGER NOT NULL, " +
                "valide INTEGER NOT NULL, " +
                "date TEXT NOT NULL, " +
                "FOREIGN KEY(idtachehebdo) REFERENCES listeTacheHebdo(_id))"
        );

    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {

    }
}
